<!doctype html>
<html>

	<head>
		<meta charset="utf-8">
		<title>出库申请审核</title>
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<link rel="stylesheet" href="../../../lib/layui-v2.5.5/css/layui.css" media="all">
	</head>

	<body>


		<!--表格结束-->


		<!--
			弹出框相关代码
		-->
		<form class="layui-form layui-form-pane" lay-filter="dataFrm" id="dataFrm">

			<div style="width: 100%;">
				<p style="font-size: 28px; margin: 3% 0% 2% 40%;">出库申请审核</p>
			</div>

			<table class="layui-hide" id="shengQingShenHe" lay-filter="shengQingShenHe"></table>
			<div style="display: none;" type="text/html" id="shengQingToolBar">
				<a class="layui-btn customer_btn_add layui-btn-sm" lay-event="add">批量审核通过</a>
				<a class="layui-btn customer_btn_batchdelete layui-btn-sm layui-btn-danger data-count-delete" lay-event="batchdelete">批量审核不通过</a>
			</div>
			<div style="display: none;" type="text/html" id="selectXQ">
				<a class="layui-btn layui-btn-xs " lay-event="update">查看详情</a>
			</div>
			<!--  是否可用 选择  -->
			<script type="text/html" id="availableTpl">
				<!-- 这里的 checked 的状态只是演示 -->
			<input type="checkbox" name="available" value="{{d.id}}" lay-skin="switch" lay-text="可用|不可用"
			    lay-filter="availableSwitch" {{ d.available == 1 ? 'checked' : '' }}>
			</script>

			
			<table id="ProductFile" lay-filter="test"></table>

			<!--修改的弹出层-->
			<div class="layui-row" id="update" style="display:none;">
				<div class="layui-col-md10" align="center">
						<table id="demo" lay-filter="test"></table>
						<div style="margin: 50px 10px 10px 0px">
							<div class="layui-form-item">
								<div class="layui-inline">
									<label style="margin-left: -600px;">总件数：<span class="sumCount"></span></label>
								</div>
								<div class="layui-inline">
									<label>合计：<span class="sumMoney"></span></label>
								</div>
							</div>
						</div>
				</div>
			</div>
		</form>
		<div style="display: none;" id="formulate3">
			<input type="text" name="title" id="title" value="0" required lay-verify="required" placeholder="输入数量" , class="layui-input">
		</div>


		<script src="../../../lib/jquery-3.4.1/jquery-3.4.1.min.js" charset="utf-8"></script>
		<script src="../../../lib/layui-v2.5.5/layui.js" charset="utf-8"></script>
		<script src="../../../lib/common/jquery.cookie.min.js" charset="utf-8"></script>
		<script src="../../../lib/common/common.js" charset="utf-8"></script>
		<script type="text/javascript">
			layui.use(['table', 'jquery', 'form'], function() {
				var ckcpxx = [];
				var oldount;
				var table = layui.table,
					layer = layui.layer,
					form = layui.form,
					$ = layui.jquery;

				var tableIns = table.render({
					elem: '#shengQingShenHe',
					url: api2 + 'outrepertory/selectShengHe',
					toolbar: "#shengQingToolBar",
					cellMinWidth: true,
					height: 'full-200',
					cols: [
						[{
								type: "checkbox",
								fixed: "left",
								width: 100
							},
							{
								field: 'o1PayId',
								title: '出库申请编号',
								width: 200,
								align: 'center'
							}, {
								field: 'o1Reason',
								title: '出库理由',
								width: 180,
								templet: '#reason',
								align: 'center'
							}, {
								field: 'o1RegisterTime',
								title: '登记时间',
								width: 240,
								align: 'center'
							}, {
								field: 'o2Amount',
								title: '总件数',
								width: 190,
								align: 'center'
							}, {
								field: 'o2Subtotal',
								title: '总金额',
								width: 190,
								align: 'center'
							}, {
								title: '操作',
								width: 190,
								templet: '#selectXQ',
								align: 'center'
							}
						]
					],
					page: true,
				});


				// table.on('edit(table)', function(obj) {
				// 	var value = obj.value //得到修改后的值
				// 		,
				// 		data = obj.data //得到所在行所有键值
				// 		,
				// 		field = obj.field; //得到字段




				// 	console.log(data)

				// if(oldount.amount>100){
				// 	layer.alert("库存不能大于库存量!")
				// }

				// });
				
				table.on('toolbar(shengQingShenHe)', function (obj) {
				    var checkStatus = table.checkStatus(obj.config.id);
				    switch (obj.event) {
				        case 'batchdelete':
				            batchNoPass();
				            break;
				        case 'add':
				            batchPass();
				            break;
				    };
				});
				
				function batchPass(){
					var checkStatus = table.checkStatus('shengQingShenHe'); //idTest 即为基础参数 id 对应的值
					var data = checkStatus.data;
					var length = checkStatus.data.length;
					console.log(checkStatus.data) //获取选中行的数据
					console.log(checkStatus.data.length) //获取选中行数量，可作为是否有选中行的条件
					if (length == 0) {
					    layer.msg("请选中要批审的产品");
					} else {
						console.log(data)
						var ids=[]
						 $.each(data,function(index,item){
							 if (index == 0) {
								  ids += "ids=" + item.o1Id;
							} else {
								  ids += "&ids=" + item.o1Id;
							}
						 })
					  $.post(api2 + "outrepertory/ShenHePass", ids, function (res) {
						  console.log(ids)
						   layer.msg(res.msg);
						   tableIns.reload();
					   });
					}
					
					
				}
				
				function batchNoPass() {
					var checkStatus = table.checkStatus('shengQingShenHe'); //idTest 即为基础参数 id 对应的值
					var data = checkStatus.data;
					var length = checkStatus.data.length;
					console.log(checkStatus.data) //获取选中行的数据
					console.log(checkStatus.data.length) //获取选中行数量，可作为是否有选中行的条件
					if (length == 0) {
					    layer.msg("请选中要批审的产品");
					} else {
						console.log(data)
						var ids=[]
						 $.each(data,function(index,item){
							 if (index == 0) {
								  ids += "ids=" + item.o1Id;
							} else {
								  ids += "&ids=" + item.o1Id;
							}
						 })
						 alert(ids)
					  $.post(api2 + "outrepertory/ShenHeNoPass", ids, function (res) {
						  console.log(ids)
						   layer.msg(res.msg);
						   tableIns.reload();
					   });
					}
				}
				
				
				var o1Id;
				var sumCount;
				var sumMoney;
				table.on('tool(shengQingShenHe)', function(obj) {
					var data = obj.data;
					if (obj.event === 'update') {
						o1Id = data.o1Id
						sumCount=data.o2Amount
						sumMoney=data.o2Subtotal
						lopen(o1Id,sumCount,sumMoney);
					}
				});

				function lopen(o1Id,sumCount,sumMoney) {
					$(".sumCount").text(sumCount)
					$(".sumMoney").text(sumMoney)
					layer.open({
						type: 1,
						title: '出库产品',
						area: ['1140px', '300px'],
						content: $('#update'), //这里content是一个DOM，注意：最好该元素要存放在body最外层，否则可能被其它的相对元素所影响
						success: function(data) {
							console.log(data)
							table.render({
								elem: '#demo',
								width: 1140,
								url: api2 + 'outrepertory/selectShengHe2?o1Id=' + o1Id, //数据接口
								cols: [
									[ //表头
										{
											field: 'o1Storer',
											title: '申请出库人',
											width: 120,
											align: 'center'
										},{
											field: 'o1Reason',
											title: '出库理由',
											width: 115,
											align: 'center',
											templet:'#reason'
										},{
											field: 'o2ProductID',
											title: '产品编号',
											width: 150,
											align: 'center'
										}, {
											field: 'o2ProductName',
											title: '产品名称',
											width: 180,
											align: 'center'
										}, {
											field: 'o2ProductDescribe',
											title: '产品描述',
											width: 170,
											align: 'center'
										}, {
											field: 'o2Amount',
											title: '出库数量',
											width: 100,
											align: 'center'
										}, {
											field: 'o2AmountUnit',
											title: '单位',
											width: 80,
											align: 'center'
										}, {
											field: 'o2CostPrice',
											title: '单价（元）',
											width: 100,
											align: 'center'
										}, {
											field: 'o2Subtotal',
											title: '总价（元）',
											width: 110,
											align: 'center'
										}
									]
								],
							});
						}
					});
				}
			});
		</script>
		<script type="text/html" id="forType">
			{{# if(d.type=='Y001-1'){d.type='商品'}}
				{{d.type}}
			{{# }else{d.type='物料'}}
				{{d.type}}
			{{# }}}
		</script>
		<script type="text/html" id="forProductClass">
			{{# if(d.productClass=='D001-1'){d.productClass='高档'}}
				{{d.productClass}}
			{{# }else if(d.productClass=='D001-2'){d.productClass='中档'}}
				{{d.productClass}}
			{{# }else{d.productClass='抵挡'}}
				{{d.productClass}}
			{{# }}}
		</script>
		<script type="text/html" id="formulate">
			<button type="button" class="layui-btn layui-btn-xs" lay-event="edit">删除</button> 
		</script>
		<script type="text/html" id="formulate2">
			<button type="button" class="layui-btn layui-btn-xs"  lay-event="edit">出库</button> 
		</script>
		<script type="text/html" id="reason">
			{{# if(d.o1Reason=='C002-1'){d.o1Reason='生产领料'}}
				{{d.o1Reason}}
			{{# }else if(d.o1Reason='C002-2'){d.o1Reason='赠送'}}
				{{d.o1Reason}}
			{{# }else if(d.o1Reason='C002-3'){d.o1Reason='内部借领'}}
				{{d.o1Reason}}
			{{# }else{d.o1Reason='其他借领'}}
				{{d.o1Reason}}
			{{# }}}
		</script>
	</body>
	<script src="../../../lib/serializejson/jquery.serializejson.js"></script>
	
</html>
